/**
 * 时间对象的格式化
 */
Date.prototype.format = function(format)
{
    /*
    * format="yyyy-MM-dd hh:mm:ss";
    */
    var o = {
        "M+" : this.getMonth() + 1,
        "d+" : this.getDate(),
        "h+" : this.getHours(),
        "m+" : this.getMinutes(),
        "s+" : this.getSeconds(),
        "q+" : Math.floor((this.getMonth() + 3) / 3),
        "S" : this.getMilliseconds()
    }

    if (/(y+)/.test(format))
    {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
            - RegExp.$1.length));
    }

    for (var k in o)
    {
        if (new RegExp("(" + k + ")").test(format))
        {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1
                ? o[k]
                : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}


//比较两个时间  time1，time2均为日期类型
//判断两个时间段是否相差 m 个月
function completeDate(time1 , time2 , m)
{
    var diffyear = time2.getFullYear() - time1.getFullYear() ;
    var diffmonth = diffyear * 12 + time2.getMonth() - time1.getMonth() ;
    if(diffmonth < 0 ){
        return false ;
    }

    var diffDay = time2.getDate() - time1.getDate() ;

    if(diffmonth < m || (diffmonth == m && diffDay <= 0)){

        if(diffmonth == m && diffDay == 0){
            var timeA = time1.getHours()*3600+60*time1.getMinutes()+time1.getSeconds();
            var timeB = time2.getHours()*3600+60*time2.getMinutes()+time2.getSeconds();
            if(timeB-timeA > 0){
                return false;
            }
        }
        return true ;
    }
    return false ;
}
